<?php
interface Idbbase {
	/**
	 * [GetTableList 获取所有字典列表]
	 */
	public function GetTableList();
	/**
	 * [GetOneTable 取得一个字典的所有信息]
	 * @param [type] $tableName [description]
	 */
	public function GetOneTable($tableName);
	/**
	 * [SearchInfo 在字典中找到一项相关内容]
	 * @param [type] $tableName [表,空为所有表]
	 * @param [type] $key [要找的内容]
	 */
	public function SearchInfo($tableName, $key);
	/**
	 * [WriteInfo 向一个表中写入数据]
	 * @param [type] $tableName [description]
	 */
	public function WriteInfo(string $tableName,array $content);
	/**
	 * [CreateNewTable 创建一个新的表]
	 * @param [type] $tableName [表名]
	 * @param [type] $detail    [字典的详细信息]
	 * @param [type] $list      [字典的详细内容]
	 */
	public function CreateNewTable($tableName,$detail,$list);
}

abstract class commonDB {
	protected $conn;
	abstract protected function init();
}

class DBFactory{
	final private function __construct(){
		return false;
	}
	final private function __clone(){
		return false;
	}
	public function GetInstance($type,$config){
		$classname = $type.'DB';
		if(class_exists($classname)){
			return new $classname($config);
		}
	}
}

class MysqlDB extends commonDB implements Idbbase {
	public function __construct($config){
		$this->init($config);
	}
	protected function init(){
		echo 'init';	
		$this->conn = null;
	}
	public function GetAllTables(){
		return 'allTable';
	}
	public function GetSearchData($key,$field){
		return 'key'.'$field';
	}
	public function GetTableCount($tableName){
		return 'count';
	}
}
/*
$a = DBFactory::GetInstance('Mysql','config');
echo $a->GetAllTables();
echo "<br>",$a->GetTableCount('table');
*/
